<html>
<script type="text/javascript" src="<?=$ROOT_JS_DIR?>/common.js"></script>
<script type="text/javascript" src="<?=$ROOT_JS_DIR?>/jsmasks.js"></script>
<body>
<h1>Loading data...</h1>
<?

define("PRIMARY_KEY","nik");
$FileName       = "ais_transaction_calc_rpc.php";
$HTMLGridName   = "CalcForm";

if (GetParam("kdtools","")) {
	$SQL = "SELECT calc_rate FROM tbltoolcalc WHERE kdtools='".GetParam("kdtools","")."'";
//	print $SQL;
	$rate = $DBConnection->dbc->get_var($SQL);
	if ($rate) {
		$js_script  = "<script>\n";
		$js_script .= "  var tarip = $rate;\n";
		$js_script .= "  var qty   = parent.document.$HTMLGridName.qty.value;\n";
		$js_script .= "  if (qty=='') qty=0;\n";
		$js_script .= "  var total = parseFloat(qty)*parseFloat(tarip);\n";		
		$js_script .= "  parent.document.$HTMLGridName.tarif.value = '$rate';\n";		
		$js_script .= "  oMask = new Mask('#,###.#0', 'number');\n";
		$js_script .= "  parent.document.$HTMLGridName.tarif.value = oMask.format(parent.document.$HTMLGridName.tarif.value);\n";
    if (GetParam("ppn","")) 
      if ($DBConnection->dbc->get_var("SELECT inc_ppn FROM tblcoa WHERE skada like '".GetParam("skada","")."'"))
        $js_script .= "  parent.document.$HTMLGridName.total.value = total*100/110;\n";
      else 
        $js_script .= "  parent.document.$HTMLGridName.total.value = oMask.format(total);\n";
    else		
		$js_script .= "  parent.document.$HTMLGridName.total.value = oMask.format(total);\n";
		$js_script .= "</script>\n";		
		print $js_script;		
	} else {
		$js_script  = "<script>\n";
		$js_script .= "  parent.document.$HTMLGridName.tarif.value = '0';\n";		
		$js_script .= "  oMask = new Mask('#,###.#0', 'number');\n";
		$js_script .= "  parent.document.$HTMLGridName.tarif.value = oMask.format('0');\n";
		$js_script .= "  parent.document.$HTMLGridName.total.value = oMask.format('0');\n";
		$js_script .= "</script>\n";		
		print $js_script;		
	}
}

?>
